﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using UnityEngine;

public class FileActionIO
{
    public static string OpenFile()
    {
        OpenFileName openFileName = new OpenFileName();
        openFileName.structSize = Marshal.SizeOf(openFileName);
        openFileName.filter = "配置文件(*.xml)\0*.xml";
        openFileName.file = new string(new char[256]);
        openFileName.maxFile = openFileName.file.Length;
        openFileName.fileTitle = new string(new char[64]);
        openFileName.maxFileTitle = openFileName.fileTitle.Length;
        openFileName.initialDir = @"C:\Users\bambom\Desktop\DEV\OP\work\Tsesy\Tsesy_Stand_Empire\Assets\OutputBundle"; //Application.streamingAssetsPath.Replace('/', '\\');//默认路径
        openFileName.title = "窗口标题";
        openFileName.flags = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000008;

        if (LocalDialog.GetSaveFileName(openFileName))
        {
            return openFileName.file;
        }
        return null;
    }
    public static string OpenFolderByUnity(string title, string path = "")
    {
        //OpenDialogDir ofn2 = new OpenDialogDir();
        //ofn2.pszDisplayName = new string(new char[2000]);// 存放目录路径缓冲区    
        //ofn2.lpszTitle = title;// 标题    
        //ofn2.initialDir = @"C:\Users\bambom\Desktop\DEV\OP\work\Tsesy\Tsesy_Stand_Sona\Assets\OutputBundle\Models";
        ////ofn2.ulFlags = BIF_NEWDIALOGSTYLE | BIF_EDITBOX; // 新的样式,带编辑框    
        //IntPtr pidlPtr = DllOpenFileDialog.SHBrowseForFolder(ofn2);

        //char[] charArray = new char[2000];
        //for (int i = 0; i < 2000; i++)
        //    charArray[i] = '\0';

        //DllOpenFileDialog.SHGetPathFromIDList(pidlPtr, charArray);
        //string fullDirPath = new String(charArray);
        //fullDirPath = fullDirPath.Substring(0, fullDirPath.IndexOf('\0'));

        //取出
#if UNITY_EDITOR
        return UnityEditor.EditorUtility.OpenFolderPanel(title, path,"");
#endif
        return "";
    }
    public static string OpenFolder(string title,string path = "")
    {
        OpenDialogDir ofn2 = new OpenDialogDir();
        ofn2.pszDisplayName = new string(new char[2000]);// 存放目录路径缓冲区    
        ofn2.lpszTitle = title;// 标题    
        ofn2.initialDir = @"C:\Users\bambom\Desktop\DEV\OP\work\Tsesy\Tsesy_Stand_Sona\Assets\OutputBundle\Models";
        //ofn2.ulFlags = BIF_NEWDIALOGSTYLE | BIF_EDITBOX; // 新的样式,带编辑框    
        IntPtr pidlPtr = DllOpenFileDialog.SHBrowseForFolder(ofn2);

        char[] charArray = new char[2000];
        for (int i = 0; i < 2000; i++)
            charArray[i] = '\0';

        DllOpenFileDialog.SHGetPathFromIDList(pidlPtr, charArray);
        string fullDirPath = new String(charArray);
        fullDirPath = fullDirPath.Substring(0, fullDirPath.IndexOf('\0'));

        //取出
        return fullDirPath;
    }
}


